package com.students.demo;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Scanner;

public class StudentManagement {
    //方法传参是Sudent List
    public static void addStudent(List<Student> students) {
        System.out.println("====添加学员信息====");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学员的学号");
        int id = scanner.nextInt();
        System.out.println("请输入学员的姓名");
        String name = scanner.next();
        System.out.println("请输入学员的性别");
        String sex = scanner.next();
        Student student = new Student(id, name, sex);
        students.add(student);
        System.out.println("添加的学员信息是:" + student);
        System.out.println("添加后学员信息是:");
        System.out.println(students);
    }

    public static void delectStudent(List<Student> students) {
        System.out.println("====请输入要删除的学员ID====");
        Scanner scanner = new Scanner(System.in);
        int delectId = scanner.nextInt();
        for (Student student : students) {
            if (Objects.equals(student.getId(), delectId)) {
                System.out.println("删除的学员信息是:" + student);
                students.remove(student);
                System.out.println("删除后的学员信息是:" + students);
            }
        }
    }

    public static void selectStudentbyid(List<Student> students) {
        System.out.println("====请输入要查询的学员ID====");
        Scanner scanner = new Scanner(System.in);
        int selectId = scanner.nextInt();
        for (Student student : students) {
            if (selectId == student.getId()) {
                System.out.println("您要查看的学员信息是:" + student);
            }
        }
    }

    public static void main(String[] args) {

        System.out.println("====初始化学员信息====");
        List<Student> students = new ArrayList<>();
        students.add(new Student(1001, "范国荣", "男"));
        students.add(new Student(1002, "范景明", "男"));
        students.add(new Student(1003, "何玉聪", "女"));
        System.out.println(students);
        while (true) {
            System.out.println("====请选择您要操作的流程====");
            System.out.println("1、根据学号查看学员信息");
            System.out.println("2、添加学员信息");
            System.out.println("3、查看所有学员信息");
            System.out.println("4、删除学员信息");
            System.out.println("5、退出系统");
            Scanner scanner = new Scanner(System.in);
            int selectNo = scanner.nextInt();
            switch (selectNo) {
                case 1:
                    selectStudentbyid(students);//根据学号查看学员信息
                    break;
                case 2:
                    addStudent(students);//添加学员信息
                    break;
                case 3:
                    System.out.println(students);//查看所有学员信息
                    break;
                case 4:
                    delectStudent(students);//删除学员信息
                    break;
                case 5:
                    System.out.println("不玩了，退出系统");
                    System.exit(0);
            }
        }
    }
}


